STEP 13: Now we need to count how many times the left arrow key is pressed. Click on the LOGIC tab to find tools.

When you add commands to an event, you must be sure they have ···· in front of them.

  • Change the variable that comes after the keyword global to left_count.

The keyword global allows us to change the value of a variable inside of an event.

To navigate the page using the TAB key, first press ESC to exit the code editor.

stage.set_background("halfcourt") sprite = codesters.Sprite("player4") sprite.go_to(215, -175) net = codesters.Sprite("basketballnet") net.go_to(215, 175) ball = codesters.Sprite("basketball") x = random.randint(-100, 150) ball.go_to(x, -25) stage.set_gravity(10) stage.set_bounce(.8) ball.set_gravity_off() net.set_gravity_off() left_count = 0 down_count = 0 def left_key(): ball.move_left(10) # add other actions... stage.event_key("left", left_key)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)